package com.baidu.service.imp;

import com.baidu.entity.*;
import com.baidu.mapper.*;
import com.baidu.util.BankCardent;
import com.baidu.util.FacePeople;
import com.baidu.util.Identy;
import com.baidu.util.People;
import com.baidu.service.CreditIdentityService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.sql.Wrapper;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 田甜
 * @version 1.0
 * @description: TODO
 * @date 2021/12/13 0013 11:08
 */
@Service
@Component
public class CreditIdentityServiceImp implements CreditIdentityService {
    @Autowired
    private TbyIdentityMapper tbyIdentityMapper;
    @Autowired
    private TbyBankcardMapper tbyBankcardMapper;
    @Autowired
    private TbyContcatmationMapper tbyContcatmationMapper;
    @Autowired
    private TCityMapper tCityMapper;
    @Override
    public void insert(TbyIdentity tbyIdentity) throws Exception {
        //完善信息第一页面输入姓名身份证号码和身份证正反面或者人脸识别的照片
        if (tbyIdentity.getSname()!=null&&tbyIdentity.getCaptruePhotos()!=null){
            People people = new People();
            String url = "https://disenforcementb.shumaidata.com/enforcement/dis/get";
            String appCode = "5458f6797b984b4f9595b34f796b0349";
            Map<String, String> params = new HashMap<>();
            params.put("idcard",tbyIdentity.getCaptruePhotos());
            params.put("name", tbyIdentity.getSname());
            String result = people.get(appCode, url, params);
            System.out.println(result);

            //不是黑名单添加身份证照片到第三方接口判断身份证Identy否则直接退出
            String urls = "https://faceidcardb.shumaidata.com/getfaceidb";
            String appCodes = "5458f6797b984b4f9595b34f796b0349";
            Map<String, String> paramss = new HashMap<>();
            paramss.put("idcard", tbyIdentity.getCaptruePhotos());
            paramss.put("name", tbyIdentity.getSname());
            //image 和 url 二选一 ，选择其中一个时，请注释另外一个参数,默认使用image
            paramss.put("url", tbyIdentity.getTheFrontSideCard());
            //params.put("image", "");
            String results = FacePeople.postForm(appCodes, urls, paramss);
            System.out.println(results);
               tbyIdentityMapper.insert(tbyIdentity);
        }
    }
    @Override
    public void bankinsert(TbyBankcard tbyBankcard) throws IOException {
        //然后到添加银行卡信息
        TbyIdentity tbyIdentity = new TbyIdentity();
        tbyIdentityMapper.selectById(tbyBankcard.getId());
        if (tbyBankcard.getBankNumber()!=null&&tbyIdentity.getSname()!=null&&tbyIdentity.getCaptruePhotos()!=null){
            String url = "https://bankcard3c.shumaidata.com/bankcard3c";
            String appCode = "5458f6797b984b4f9595b34f796b0349";
            Map<String, String> params = new HashMap<>();
             tbyIdentity.getSname();
             tbyIdentity.getCaptruePhotos();
             tbyBankcard.getBankNumber();
            //姓名：刘冬奇
            //身份证：360428198201011432
            //银行卡号：6217856100044522370
            params.put("idcard",  tbyIdentity.getCaptruePhotos());
            params.put("name", tbyIdentity.getSname());
            params.put("bankcard",  tbyBankcard.getBankNumber());
            String result = BankCardent.get(appCode, url, params);
            System.out.println(result);
            tbyBankcardMapper.insert(tbyBankcard);
        }
    }

    @Override
    public void catmationinsert(TbyContcatmation tbyContcatmation) {
        String theAddress = tbyContcatmation.getTheAddress();
        System.out.println(theAddress);
        if (theAddress=="青海"||theAddress=="西藏"){

        }else{

        }
        tbyContcatmationMapper.insert(tbyContcatmation);
    }
    @Override
    public void selectByid(Integer did) {

        tCityMapper.cityByid(did);
    }
}
